package wexin.web.test;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import wexin.web.jpa.domain.Customer;
import wexin.web.jpa.domain.Gender;
import wexin.web.jpa.domain.Product;
import wexin.web.jpa.domain.User;

@Controller
public class HomeController {
    User user = new User();
    //入口
    @RequestMapping(value = "/home")
    public String home(Model model) {
        model.addAttribute("user",user);
        return "aa";
    }

 //提交表单后进行数据读取，并将数据传出
    @RequestMapping(value = "/bb",method = RequestMethod.POST)
    public String bb(User user,Model model,HttpRequest request) {
        model.addAttribute("user", user);
        System.out.println(user.getName());
        model.addAttribute("message", ",welcome");
        return "bb";
    }
    
    @RequestMapping(value = "/cc",method = RequestMethod.GET)
    public String cc(Model model,HttpRequest request) {
    	List<Product> productList = new ArrayList<Product>();
    	Product p = new Product();
    	p.setDescription("青春学堂");
    	p.setAvailableFrom(new Date());
    	p.setPrice(100.1);
    	productList.add(p) ;
    	
    	Product p1 = new Product();
    	p1.setDescription("广州大咖");
    	p1.setAvailableFrom(new Date());
    	p1.setPrice(200.1);
    	productList.add(p1) ;
    	
        model.addAttribute("productList", productList);
        return "cc";
    }
    
    
    @RequestMapping(value = "/dd",method = RequestMethod.GET)
    public String dd(Model model,HttpRequest request) {
    	Product p = new Product();
    	p.setDescription("青春学堂");
    	p.setAvailableFrom(new Date());
    	p.setPrice(100.1);
    	
        model.addAttribute("product", p);
        return "dd";
    }
    
    @RequestMapping(value = "/ee",method = RequestMethod.GET)
    public String ee(Model model,HttpRequest request) {
    	Customer  c= new Customer();
    	//c.setGender(Gender.FEMALE);
        model.addAttribute("customer", c);
        return "dd";
    }
    
    @RequestMapping(value = "/ff",method = RequestMethod.GET)
    public String ff(Model model) {
    	User user = new User();
    	user.setName("li72") ;
    	//c.setGender(Gender.FEMALE);
        model.addAttribute("resumes", user);
        model.addAttribute("resume", user);
        return "ff";
    }
    
    @RequestMapping(value = "/gg",method = RequestMethod.GET)
    public String gg(Model model,HttpRequest request) {
    	Customer  c= new Customer();
    	c.setGender(Gender.FEMALE);
        model.addAttribute("resume", c);
        return "gg";
    }
}